/**
 * 
 */
package com.hoopchina.ui.main;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.hoopchina.news.R;
import com.hoopchina.util.TimeUtils;

import android.content.Context;
import android.content.res.ColorStateList;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
   NewsListItemView
 * 列表显示新闻条目的view
 * 
 * @author Neusoft
 */
public class NewsListItemView extends RelativeLayout {
	private Context  mContext;
	private TextView mTitle;
	private Button   mGoNewsDetail;
	private Button   mHavaImage;
	private TextView mSummary;
	private TextView mFrom;
	private TextView mUpdateTime;
	private String   mRawTime;
	

    public String getRawTime() {
		return mRawTime;
	}



	public void setRawTime(String mRawTime) {
		this.mRawTime = mRawTime;
	}



	public NewsListItemView( Context context ) {
        super( context );
        init(context);
    }



    public NewsListItemView( Context context, AttributeSet attrs ) {
        super( context, attrs );
        init(context);
    }


    public String getTitle() {
        return mTitle.getText().toString();
    }


    public void setTitle( String mTitle ) {
        this.mTitle.setText( mTitle.trim() );
    }


    public Button getGoNewsDetail() {
        return mGoNewsDetail;
    }


    public void setGoNewsDetail( Button mGoNewsDetail ) {
        this.mGoNewsDetail = mGoNewsDetail;
    }
    

    public String getSummary() {
        return mSummary.getText().toString();
    }

    /**
     * 设置摘要文本
     * @param mSummary
     */
    public void setSummary( String mSummary ) {
        this.mSummary.setText( mSummary );
    }
    
    /**
     * 设置摘要文本颜色
     * @param mSummary
     */
    public void setSummaryColor( ColorStateList colors) {
        this.mSummary.setTextColor( colors);
    }
    /**
     * 单一颜色
     * @param color
     */
    public void setSummaryColor( int color) {
        this.mSummary.setTextColor( color);
    }

    /**
     * 设置标题文本颜色
     * @param mSummary
     */
    public void setTitleColor( ColorStateList colors ) {
    	mTitle.setTextColor(colors);
    }
    /**
     * 单一颜色
     * @param colors
     */
    public void setTitleColor( int color ) {
    	mTitle.setTextColor(color);
    }
    public String getFrom() {
        return mFrom.getText().toString();
    }


    public void setFrom( String from ) {
        this.mFrom.setText( mContext.getString(R.string.news_list_item_from) + from );
    }


    public String getUpdateTime() {
        return mUpdateTime.getText().toString();
    }

    /**
     * 设置新闻更新的时间
     * @param updateTime 时间字符串
     */
	public void setUpdateTime(String updateTime) {
		mUpdateTime.setText(TimeUtils.getUpdateTime(updateTime));
	}

    /**
     * 初始化数据
     * @param context  上下文对象
     */
    public void init( Context context )
    {
        mContext = context;
        String infServiString = Context.LAYOUT_INFLATER_SERVICE;
        LayoutInflater lInflater;
        lInflater = ( LayoutInflater ) getContext().getSystemService( infServiString );
        lInflater.inflate( R.layout.newslistitem, this, true );
        
        mTitle = (TextView)findViewById( R.id.textViewListItemTitle );
        mGoNewsDetail = (Button)findViewById( R.id.buttonListItemGoDetail );
        mHavaImage = (Button)findViewById( R.id.buttonListItemLogo );
        mSummary = (TextView)findViewById( R.id.textViewListItemSummary );
        mFrom = (TextView)findViewById( R.id.textViewListItemFrom );;
        mUpdateTime = (TextView)findViewById( R.id.textViewListItemUpdateTime );
    }


	public boolean isHaveImage() {
		return ( mHavaImage.getVisibility() == Button.VISIBLE ) ? true : false;
	}


	public void setHaveImage(boolean isHaveImage) {
		if (isHaveImage) {
			mHavaImage.setVisibility(Button.VISIBLE);
		}
		else {
			mHavaImage.setVisibility(Button.INVISIBLE);
		}
	}
	

    public void setHaveImage( String isHaveImage ) {
        if ( null == isHaveImage || isHaveImage.equals("0") ) {
            this.mHavaImage.setVisibility( Button.INVISIBLE);
        } 
        else {
            this.mHavaImage.setVisibility( Button.VISIBLE );
        }
    }
	

}
